package com.xhd.im;

import java.util.Vector;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;
import com.xhd.base.session.SessionManager;
import com.xhd.server.ServerConfig;
import com.xhd.util.XThread;

public class OnlineCheckThread extends XThread
{
  private long jm362 = 0L;
  private final long jm363 = ServerConfig.RefreshOnlineMinutes * 60000;
  private final long jm364 = 3600000L;
  private static final Log jm9;
  static Class jm10;

  static
  {
    Class tmp3_0 = jm10;
    if (tmp3_0 == null)
    {
     
      try
      {
         OnlineCheckThread.jm10 = Class.forName("com.sinocc.base.im.OnlineCheckThread");
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
      }
    }
    jm9 = LogFactory.getLog(tmp3_0);
  }

  public OnlineCheckThread()
  {
    super("Check Online Thread");
  }

  public void run()
  {
    WaitConnectList localWaitConnectList = WaitConnectList.getInstance();
    SessionManager localSessionManager = SessionManager.getInstance();
    OnlineMgr localOnlineMgr = OnlineMgr.getInstance();
    long l1 = System.currentTimeMillis();
    try
    {
      sleep(1000L);
    }
    catch (InterruptedException localInterruptedException1)
    {
    }
    while (!(this.stop))
    {
      try
      {
        sleep(1000L);
      }
      catch (InterruptedException localInterruptedException2)
      {
        if (this.stop)
          return;
      }
      try
      {
        Vector localVector = localWaitConnectList.getTimeoutAndRemove(ServerConfig.OnlineTimeOutMinutes);
        if ((localVector != null) && (localVector.size() > 0))
        {
          int i = localVector.size();
          for (int j = 0; j < i; ++j)
          {
            String str = (String)localVector.get(j);
            if (!(localSessionManager.setOnline(str, false)))
              continue;
            localOnlineMgr.onChanged(str, true);
          }
          jm9.trace("Check online " + i);
        }
        long l2 = System.currentTimeMillis();
        if (this.jm362 + this.jm363 < l2)
        {
          localOnlineMgr.syncOnline();
          this.jm362 = l2;
          l1 = System.currentTimeMillis();
        }
        if (l1 + 3600000L < l2)
        {
          if (2 == ServerConfig.ServerType)
            SessionManager.getInstance().checkAll(l1);
            l1 = System.currentTimeMillis();
        }
      }
      catch (Throwable localThrowable)
      {
        jm9.error(localThrowable);
      }
    }
  }
}